package com.tracker.util;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;



public class MasterInformation {

	private static Map<String, String> branches = new HashMap<String, String>();
	private static Map<String,String> branchesByDesc = new HashMap<String, String>();
	
	private static Map<String, String> getBranchesInfo() {
		TrackerConnection tConn = new TrackerConnection();
		Connection connection = null;
		PreparedStatement pStmt = null;
		ResultSet rs = null;
		try {
			connection = tConn.getConnection();
			pStmt = connection.prepareStatement("SELECT Brncode,Description FROM branch");
			rs = pStmt.executeQuery();
			String bCode = null;
			String bDescription = null;
			while(rs.next()) {
				bCode = rs.getString("Brncode");
				bDescription = rs.getString("Description");
				branches.put((bCode == null)?" ":bCode,(bDescription == null)?"":bDescription);
				branchesByDesc.put((bDescription == null)?" ":bDescription,(bCode == null)?"":bCode);
				
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return branches;
	}
	
	public static Map<String,String> getBranches() {
		if(branches.size() == 0) {
			getBranchesInfo();
		}
		return branches;
	}
	
	public static Map<String,String> getBrancheCodeByDesc() {
		if(branchesByDesc.size() == 0) {
			getBranchesInfo();
		}
		return branchesByDesc;
	}
}
